<template>
  <div>
    <h1>医生管理</h1>
    <el-divider></el-divider>
    <el-table :data="staffList">
      <el-table-column prop="id" label="序号" min-width="80"></el-table-column>
      <el-table-column prop="avatar" label="头像" min-width="120">
        <template v-slot="{ row }">
          <img :src="baseUrl + row.avatar" style="height: 60px;" alt="">
        </template>
      </el-table-column>
      <el-table-column prop="name" label="姓名" min-width="120"></el-table-column>
      <el-table-column prop="title" label="职称" min-width="120"></el-table-column>
      <el-table-column prop="school" label="毕业院校" min-width="120"></el-table-column>
      <el-table-column prop="tags" label="擅长领域" min-width="140">
        <template v-slot="{ row }">
          <el-space wrap>
            <el-tag round v-for="(item, index) in row.tags" :key="index" type="primary">{{ item }}</el-tag>
          </el-space>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" min-width="120">
        <template v-slot="{ row }">
          <el-tag type="primary" v-if="row.status === 1">启用</el-tag>
          <el-tag type="danger" v-else>禁用</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <br>
    <el-pagination @size-change="sizeChange" :page-sizes="[2, 5, 10, 15, 20]" @current-change="pageChange" background
      layout="pre,pager,next,sizes,jumper" :total="staffTotal" v-model:page-size="size"></el-pagination>
  </div>
</template>

<script setup>
import { getStaffList, getStaffTotal, staffRemove } from '@/utils/api'
import { onMounted, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const route = useRoute()
const router = useRouter()
const { bus_id } = route.query
if (!bus_id) {
  ElMessage.warning('参数错误')
  router.push('/business');
}
const staffList = ref([])
const staffTotal = ref(0)
const page = ref(1)
const size = ref(5)
const getStaffListAction = async () => {
  const { data } = await getStaffList({ page: page.value, size: size.value, bus_id })
  if (data.code === 200) {
    staffList.value = data.data
  }
}
const getStaffTotalAction = async () => {
  const { data: countData } = await getStaffTotal({ page: page.value, size: size.value, bus_id })
  staffTotal.value = countData.data
}
const updateStaff = () => {
  getStaffListAction({ page: page.value, size: size.value, bus_id })
  getStaffTotalAction({ bus_id })
}
onMounted(async () => {
  updateStaff()
})
const pageChange = (num) => {
  page.value = num
  // 重新发送请求
  getStaffListAction({ page: page.value, size: size.value, bus_id })
}
const sizeChange = (num) => {
  size.value = num
  // 重新发送请求
  getStaffListAction({ page: page.value, size: size.value, bus_id })
}

</script>

<style></style>